<?php

namespace common\modules\wechat\rules;

use common\components\Rule;
use common\modules\wechat\models\Account;
use Yii;

/**
 * 检查用户是否有指定微信ID的权限
 *
 * @package common\modules\wechat\rules
 */
class WechatOwnerRule extends Rule
{
    /**
     * @inheritdoc
     */
    public $name = 'wechatOwner';

    /**
     * @inheritdoc
     */
    public function execute($user, $item, $params)
    {
        // 读取当前的公众号ID
        /** @var Account $account */
        $account = Account::findOne(Yii::$app->request->get('id'));

        return $account->created_by == $user;
    }
}
